package cn.stylefeng.guns.modular.ums.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ums.entity.MemberRecommendRecords;
import cn.stylefeng.guns.modular.ums.mapper.MemberRecommendRecordsMapper;
import cn.stylefeng.guns.modular.ums.model.params.MemberRecommendRecordsParam;
import cn.stylefeng.guns.modular.ums.model.result.MemberRecommendRecordsResult;
import  cn.stylefeng.guns.modular.ums.service.MemberRecommendRecordsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 教师推广记录表 服务实现类
 * </p>
 *
 * @author yzb
 * @since 2019-11-07
 */
@Service
public class MemberRecommendRecordsServiceImpl extends ServiceImpl<MemberRecommendRecordsMapper, MemberRecommendRecords> implements MemberRecommendRecordsService {

    @Override
    public void add(MemberRecommendRecordsParam param){
        MemberRecommendRecords entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MemberRecommendRecordsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MemberRecommendRecordsParam param){
        MemberRecommendRecords oldEntity = getOldEntity(param);
        MemberRecommendRecords newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MemberRecommendRecordsResult findBySpec(MemberRecommendRecordsParam param){
        return null;
    }

    @Override
    public List<MemberRecommendRecordsResult> findListBySpec(MemberRecommendRecordsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(MemberRecommendRecordsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(MemberRecommendRecordsParam param){
        return param.getRecordsId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MemberRecommendRecords getOldEntity(MemberRecommendRecordsParam param) {
        return this.getById(getKey(param));
    }

    private MemberRecommendRecords getEntity(MemberRecommendRecordsParam param) {
        MemberRecommendRecords entity = new MemberRecommendRecords();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
